const config = require("../../mfo.config.js");
const t = require("../../config/dict");
const chalk = require("chalk");
const { checkCustomProfile, log } = require("../utils");
const configLang = require("../configLang");
const version = require("./version");

module.exports = (projectRoot, lang) => {
  checkCustomProfile();
  let _LOCALSOURCE = process.env.LOCALSOURCE || config.LOCALSOURCE;
  let context = {
    name: projectRoot,
    root: projectRoot,
    source: _LOCALSOURCE,
    lang,
  };
  const init = (context) => {
    return version(context).then((context) => {
      log("tip", {
        message: chalk.blue(
          [
            t(context.lang, "开始创建"),
            projectRoot,
            t(context.lang, "项目"),
            "...",
          ].join(" ")
        ),
      });
      return context;
    });
  };

  return configLang(context, init);
};
